import Mock from 'mockjs2'
import {builder, getQueryParameters} from "@/mock/util";


const groupList = (options) => {
	console.log(' mock: user group list')
	console.log(options)
	const data = []
	for (let i =0;i<30;i++){
		const group = {
			"id": i,
			"name": "group" + i,
			"type": 0,
			"internalName": "cg_" + i,
			"cron": "",
			"config": "{\"condition\":\"AND\",\"user_rule\":{\"index\":0,\"condition\":\"AND\",\"rules\":[{\"index\":0,\"property\":\"users.first_utm_content\",\"operator\":\"contain\",\"values\":[],\"value\":\"1234\"}],\"filters\":[]},\"event_rule\":{\"condition\":\"AND\",\"rules\":[{\"key\":\"c56588d7v5\",\"done\":true,\"type\":\"event_rule\",\"time\":{\"type\":\"absolute_time\",\"values\":[\"2022-09-22\",\"2022-09-29\"]},\"event\":\"PageView\",\"measure\":{\"name\":\"count\",\"value\":\"${events#event.count(#cdt#).NULL}\"},\"operator\":\"equal\",\"values\":[0],\"filter\":{\"index\":0,\"condition\":\"AND\",\"rules\":[],\"filters\":[]}}]},\"actions_rule\":{\"condition\":\"AND\",\"rules\":[{\"time\":{\"type\":\"absolute_time\",\"values\":[\"2022-09-22\",\"2022-09-29\"]},\"actions\":[{\"name\":1,\"event\":\"Login\",\"filter\":{\"index\":0,\"condition\":\"AND\",\"rules\":[],\"filters\":[]}},{\"name\":2,\"event\":\"Purchase\",\"filter\":{\"index\":0,\"condition\":\"AND\",\"rules\":[],\"filters\":[]}}],\"id\":\"A\"}]}}",
			"exportConfig": "",
			"projectId": "",
			"orgId": 1,
			"datasourceId": 1,
			"status": 1,
			"users": 100,
			"message": "",
			"updatedAt": "2022-08-11 00:00:00",
			"createdAt": "2022-08-11 00:00:00",
			"userGroupExportTasks":{
				"id": i * 10,
				"projectId": "",
				"userGroupInternalName": "",
				"filePath": "",
				"config": "",
				"type": 0,
				"status": 0,
				"duration": 100,
				"updatedAt": "2022-08-11 00:00:00",
				"createdAt": "2022-08-11 00:00:00"
			}
		}
		data.push(group)
	}


	return builder(data)
}

const metaUserProperties = (options) => {
	console.log(' mock: meta user property list')
	console.log(options)
	const data = [
		{"id":1,"name":"id","displayName":"主键Id","dataType":0,"dict":false,"unit":"","visibility":false,"remark":"自动生成的uuid","type":0,"userField":null},
		{"id":2,"name":"first_id","displayName":"匿名Id","dataType":0,"dict":false,"unit":"","visibility":false,"remark":"对应事件属性中的distinct_id","type":0,"userField":null},
		{"id":3,"name":"second_id","displayName":"登录ID","dataType":0,"dict":false,"unit":"","visibility":false,"remark":"在业务系统中的登录用户id","type":0,"userField":null},
		{"id":7,"name":"phone","displayName":"手机号","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},
		{"id":6,"name":"first_utm_content","displayName":"首次访问广告内容","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},
		{"id":5,"name":"first_utm_term","displayName":"首次访问广告关键词","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},
		{"id":4,"name":"first_utm_campaign","displayName":"首次访问推广活动","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},
		{"id":8,"name":"first_utm_medium","displayName":"首次访问投放方式","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},
		{"id":9,"name":"first_utm_source","displayName":"首次访问投放渠道","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":1,"name":"first_visit_time","displayName":"首次访问时间","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":40,"name":"gender","displayName":"性别","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":39,"name":"cg_73","displayName":"车险用户推广","dataType":2,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":38,"name":"cg_72","displayName":"页面浏览","dataType":2,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":41,"name":"vip_level","displayName":"VIP等级","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":42,"name":"city","displayName":"用户所属城市","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":43,"name":"province","displayName":"用户所属省份","dataType":0,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":44,"name":"cg_74","displayName":"近一周已下单未支付用户","dataType":2,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":45,"name":"cg_75","displayName":"近一周流失用户","dataType":2,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":46,"name":"cg_76","displayName":"高活跃度用户","dataType":2,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null},{"id":47,"name":"cg_77","displayName":"低活跃度用户","dataType":2,"dict":false,"unit":"","visibility":true,"remark":"","type":1,"userField":null}]
	return builder(data)
}



Mock.mock(/^.*?\/smartreportservice\/usergroup\?.*?/, 'get', groupList)
Mock.mock(/^.*?\/smartreportservice\/datasource\/\w*\/metadata\/user\/property\?.*?/, 'get', metaUserProperties)
